package com.ktjy.temp.mqtt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ktjy.temp.mqtt.mapper.DeviceDataMapper;
import com.ktjy.temp.mqtt.service.DeviceDataService;
import com.ktjy.temp.pojo.DeviceData;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeviceDataServiceImp implements DeviceDataService {

    @Resource
    DeviceDataMapper deviceDataMapper;

    @Override
    public int addDeviceData(DeviceData deviceData) {
        return deviceDataMapper.insert(deviceData);
    }

    public List<DeviceData> getDeviceDataBySensorId(String sensorId,int size) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("sensor_id", sensorId);
        queryWrapper.orderByDesc("collect_time");
        queryWrapper.last("limit " + size);
        return deviceDataMapper.selectList(queryWrapper);
    }
}
